package cn.tedu.boot08.controller;


import cn.tedu.boot08.entity.Banner;
import cn.tedu.boot08.mapper.BannerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.List;

@RestController
public class BannerController {
    @Autowired
    BannerMapper mapper;
    @RequestMapping("/insert")
    public void insert(@RequestBody Banner banner){
        System.out.println("banner = " + banner);
        mapper.insert(banner);
        /*
        use birddb;
        create table banner(id int primary key auto_increment,
        url varchar(255),des varchar(100));
        * */
    }
    @RequestMapping("/select")
    public List<Banner> select(){
        return mapper.select();
    }
    @RequestMapping("/delete")
    public void delete(int id){
        //通过轮播图对象的id查询到图片的路径
        String url = mapper.selectUrlById(id);
        new File("g:/files"+url).delete();

        mapper.deleteById(id);
    }
}
